<?php
/**
 * @author Mazvv
 * @package Cities
 */
class Advertises extends CRM_Controller {
	
	public function __construct(){
		parent::__construct();
		$this->a_identifier = 'advertises';
		$this->lang->load('advertises');
		$this->load->model('advertises_model');
		$this->load->model('currencies_model');
		$this->load->model('advertisessources_model');
		$this->load->model('advertisescompanies_model');
		$this->load->model('filials_model');
		$this->load->model('cities_model');
		$this->SetNewToolSize('550x460');
		$this->SetEditToolSize('550x460');
		$this->SetDetailsToolSize('550x460');
		$this->SetFindToolSize('550x360');
		
		
		$this->a_validation_rules['date_doc'] = "required";

		$this->a_validation_rules['_currencies_rid'] = "required";   
		$this->a_validation_rules['_cities_rid'] = "required";   
		$this->a_validation_rules['_advertisessources_rid'] = "required";     
		$this->a_validation_rules['_advertisescompanies_rid'] = "required";    
		$this->a_validation_rules['bdate'] = "required";         
		$this->a_validation_rules['edate'] = "required";        
		$this->a_validation_rules['oper_date'] = "required"; 
		$this->a_validation_rules['summ_value'] = "required";         
		$this->a_validation_rules['advertises_name'] = "required";
		//$this->a_validation_rules['oper_type'] = "required";
			
		$this->a_validation_fields['date_doc'] = $this->lang->line('DATE_DOC');
		$this->a_validation_fields['_currencies_rid'] = $this->lang->line('CURRENCY');
		$this->a_validation_fields['_cities_rid'] = $this->lang->line('CITY');
		$this->a_validation_fields['_filials_rid'] = $this->lang->line('FILIAL');
		$this->a_validation_fields['_advertisessources_rid'] = $this->lang->line('ADVERTISE');
		$this->a_validation_fields['_advertisescompanies_rid'] = $this->lang->line('ACOMPANY'); 
		$this->a_validation_fields['bdate'] = $this->lang->line('BDATE'); 
		$this->a_validation_fields['edate'] = $this->lang->line('EDATE');
		$this->a_validation_fields['oper_date'] = $this->lang->line('PDATE'); 
		$this->a_validation_fields['summ_value'] = $this->lang->line('PRICE');
		$this->a_validation_fields['advertises_name'] = $this->lang->line('NAME');  
		$this->a_validation_fields['oper_type'] = $this->lang->line('PLANED');
		
		$this->a_validation_fields['descr'] = $this->lang->line('DESCR');
		$this->a_validation_fields['archive'] = $this->lang->line('ARCHIVE');
		$this->a_validation_fields['modifyDT'] = $this->lang->line('ARCHIVE');
		$this->validation->set_rules($this->a_validation_rules);
		$this->validation->set_fields($this->a_validation_fields);
		
		
		$this->objectsList['MENU_OBJECT'] = $this->menucontainer->RenderVerticalTreeMenu();
		
	}
	
	public function _remap($m_cif_name){
		switch ($m_cif_name) {
			case 'nJ': {echo $this->_create();break;}
			case 'eJ': {echo $this->_edit();break;}
			case 'dJ': {echo $this->_details();break;}
			case 'rJ': {echo $this->_remove();break;}
			case 'fJ'; {echo $this->_find();break;}
			case 'uJ'; {echo $this->_refresh();break;}
			case 'srt'; {$this->_sort();break;}
			case 'ar'; {$this->_activerecord();break;}
			case 'sar'; {$this->_setactiverecord();break;}
			case 'pg':{echo $this->_journal();break;}
			default: $this->_index();
		}
	}
	
	protected function _index(){
		$this->objectsList['GRID_OBJECT'] = $this->_journal();
		$this->load->view('layouts/main_layout', $this->objectsList);
	}
	
	public function _journal(){
		
		$content = array();
		$content['title'] = $this->lang->line('DICTIONARY_TITLE'); 
		$content['rid'] = 'ID'; 

		$content['date_doc'] = $this->lang->line('DATE_DOC');
		$content['currency_code'] = $this->lang->line('CURRENCY');
		$content['source_name'] = $this->lang->line('ADVERTISE');
		$content['company_name'] = $this->lang->line('ACOMPANY');
		$content['filial_name'] = $this->lang->line('FILIAL'); 
		$content['city_name'] = $this->lang->line('CITY'); 
		$content['bdate'] = $this->lang->line('BDATE'); 
		$content['edate'] = $this->lang->line('EDATE'); 
		$content['oper_date'] = $this->lang->line('PDATE'); 
		$content['summ_value'] = $this->lang->line('PRICE'); 
		
		$content['archive'] =  $this->lang->line('ARCHIVE');
		$content['modifyDT'] =  $this->lang->line('MODIFYDT');
		$content['yes'] = $this->lang->line('YES');
		$content['no'] = $this->lang->line('NO');
		$content['tools'] = $this->GetTools(); 
		$content['DS'] = $this->advertises_model->GetDS();
		$content['pagination'] = $this->GetPagination();
		if($content['DS'] && !$this->GetSessionData('activerecord')) $this->SetSessionData('activerecord', $content['DS'][0]->rid);
		$content['activerecord'] = $this->GetSessionData('activerecord');	
		//echo $content['activerecord'];
		return $this->load->view('advertises/journal', $content, True);		
	}
	
	private function _create(){
		if ($this->validation->run() == FALSE){
			$content = array();
			$content['header'] = $this->load->view('standart/tmpl/header', array('title'=>$this->lang->line('DICTIONARY_TITLE_CREATE')), True);
			$content['title'] = $this->lang->line('DICTIONARY_TITLE_CREATE'); 
			# { date_doc
			$content['date_doc'] = $this->RenderLabel('date_doc');
			$data = array('name'=>'date_doc', 'id'=>'date_doc', 'size'=>'12', 'value'=>$this->validation->date_doc?$this->validation->date_doc:date('d.m.Y'), 'readonly'=>'readonly');
			$content['date_doc_field'] =  form_input($data);
			# } date_doc

			# { advertises_name
			$content['advertises_name'] = $this->RenderLabel('advertises_name');
			$content['advertises_name_field'] =  form_input('advertises_name', $this->validation->advertises_name?$this->validation->advertises_name:'');
			# } advertises_name
			
			# { _currencies_rid
			$content['_currencies_rid'] = $this->RenderLabel('_currencies_rid');
			$content['_currencies_rid_field'] =  form_dropdown('_currencies_rid', $this->currencies_model->GetPairArr(), $this->validation->_currencies_rid?$this->validation->_currencies_rid:'');
			# } _currencies_rid
			
			# { _cities_rid
			$content['_cities_rid'] = $this->RenderLabel('_cities_rid');
			$content['_cities_rid_field'] =  form_dropdown('_cities_rid', $this->cities_model->GetPairArr(), $this->validation->_cities_rid?$this->validation->_cities_rid:'');
			# } _cities_rid
			
			# { _advertisessources_rid
			$content['_advertisessources_rid'] = $this->RenderLabel('_advertisessources_rid'); 
			$content['_advertisessources_rid_field'] =  form_dropdown('_advertisessources_rid', $this->advertisessources_model->GetPairArr(), $this->validation->_advertisessources_rid?$this->validation->_advertisessources_rid:'');
			# } _advertisessources_rid

			# { _advertisescompanies_rid
			$content['_advertisescompanies_rid'] = $this->RenderLabel('_advertisescompanies_rid'); 
			$content['_advertisescompanies_rid_field'] =  form_dropdown('_advertisescompanies_rid', $this->advertisescompanies_model->GetPairArr(), $this->validation->_advertisescompanies_rid?$this->validation->_advertisescompanies_rid:'');
			# } _advertisescompanies_rid
			
			# { _filials_rid
			$content['_filials_rid'] = $this->RenderLabel('_filials_rid'); 
			$content['_filials_rid_field'] =  form_dropdown('_filials_rid', $this->filials_model->GetPairArr(), $this->validation->_filials_rid?$this->validation->_filials_rid:'');
			# } _filials_rid
			
			# { bdate 
			$content['bdate'] = $this->RenderLabel('bdate');
			$data = array('name'=>'bdate', 'id'=>'bdate', 'value'=>$this->validation->bdate?$this->validation->bdate:'', 'size'=>'12', 'readonly'=>'readonly');
			$content['bdate_field'] =  form_input($data).$this->RenderCalendar('bdate');
			# } bdate
			
			# { edate
			$content['edate'] = $this->RenderLabel('edate');
			$data = array('name'=>'edate', 'id'=>'edate', 'value'=>$this->validation->edate?$this->validation->edate:'', 'size'=>'12', 'readonly'=>'readonly');
			$content['edate_field'] =  form_input($data).$this->RenderCalendar('edate');
			# } edate

			# { oper_date
			$content['oper_date'] = $this->RenderLabel('oper_date');
			$data = array('name'=>'oper_date', 'id'=>'oper_date', 'value'=>$this->validation->oper_date?$this->validation->oper_date:'', 'size'=>'12', 'readonly'=>'readonly');
			$content['oper_date_field'] =  form_input($data).$this->RenderCalendar('oper_date');
			# } oper_date

			# { oper_type
			$content['oper_type'] = $this->RenderLabel('oper_type');
			$content['oper_type_field'] =  form_checkbox('oper_type', 'F', $this->validation->oper_type=='F'?True:False);
			# } oper_type
			
			# { summ_value
			$content['summ_value'] = $this->RenderLabel('summ_value');
			$content['summ_value_field'] =  form_input('summ_value', $this->validation->summ_value?$this->validation->summ_value:'');
			# } summ_value
			
			# { descr
			$content['descr'] =  $this->lang->line('DESCR');
			$data = array('name'=>'descr', 'id'=>'descr', 'cols'=>'50', 'rows'=>'2', 'value'=>$this->validation->descr?$this->validation->descr:''); 
			$content['descr_field'] =  form_textarea($data);
			# } descr

			# { archive
			$content['archive'] =  $this->lang->line('ARCHIVE');
			$content['archive_field'] =  form_dropdown('archive', array('0'=>$this->lang->line('NO'), '1'=>$this->lang->line('YES')), $this->validation->archive?$this->validation->archive:'');
			# } archive
			
			# { modifyDT
			$content['modifyDT'] =  $this->lang->line('MODIFYDT');
			$content['modifyDT_field'] =  form_input('modifyDT', $this->validation->modifyDT?$this->validation->modifyDT:'');
			# } modifyDT
			return $this->load->view('advertises/create', $content, True);
		}
		if($insRid = $this->advertises_model->CreateRecord()){
			$this->SetSessionData('activerecord', $insRid);
			$this->load->view('standart/tmpl/create_success', array('identifier'=>$this->GetIdentifier()));
		}
	}
	
	private function _edit(){
		if($activerecord=$this->uri->segment(3)) $this->_setactiverecord($activerecord);
		if ($this->validation->run() == FALSE){
			$content = array();
			$content['DS'] = $this->advertises_model->GetEditDS();
			$content['header'] = $this->load->view('standart/tmpl/header', array('title'=>$this->lang->line('DICTIONARY_TITLE_CREATE')), True);
			$content['title'] = $this->lang->line('DICTIONARY_TITLE_CREATE'); 
			# { date_doc
			$content['date_doc'] = $this->RenderLabel('date_doc');
			$data = array('name'=>'date_doc', 'id'=>'date_doc', 'size'=>'12', 'value'=>$this->validation->date_doc?$this->validation->date_doc:$content['DS']->date_doc, 'readonly'=>'readonly');
			$content['date_doc_field'] =  form_input($data);
			# } date_doc
			
			# { advertises_name
			$content['advertises_name'] = $this->RenderLabel('advertises_name');
			$content['advertises_name_field'] =  form_input('advertises_name', $this->validation->advertises_name?$this->validation->advertises_name:$content['DS']->advertises_name);
			# } advertises_name
			
			# { _currencies_rid
			$content['_currencies_rid'] = $this->RenderLabel('_currencies_rid');
			$content['_currencies_rid_field'] =  form_dropdown('_currencies_rid', $this->currencies_model->GetPairArr(), $this->validation->_currencies_rid?$this->validation->_currencies_rid:$content['DS']->_currencies_rid);
			# } _currencies_rid
			
			# { _cities_rid
			$content['_cities_rid'] = $this->RenderLabel('_cities_rid');
			$content['_cities_rid_field'] =  form_dropdown('_cities_rid', $this->cities_model->GetPairArr(), $this->validation->_cities_rid?$this->validation->_cities_rid:$content['DS']->_cities_rid);
			# } _cities_rid
			
			# { _advertisessources_rid
			$content['_advertisessources_rid'] = $this->RenderLabel('_advertisessources_rid'); 
			$content['_advertisessources_rid_field'] =  form_dropdown('_advertisessources_rid', $this->advertisessources_model->GetPairArr(), $this->validation->_advertisessources_rid?$this->validation->_advertisessources_rid:$content['DS']->_advertisessources_rid);
			# } _advertisessources_rid

			# { _advertisescompanies_rid
			$content['_advertisescompanies_rid'] = $this->RenderLabel('_advertisescompanies_rid'); 
			$content['_advertisescompanies_rid_field'] =  form_dropdown('_advertisescompanies_rid', $this->advertisescompanies_model->GetPairArr(), $this->validation->_advertisescompanies_rid?$this->validation->_advertisescompanies_rid:$content['DS']->_advertisescompanies_rid);
			# } _advertisessources_rid
			
			# { _filials_rid
			$content['_filials_rid'] = $this->RenderLabel('_filials_rid'); 
			$content['_filials_rid_field'] =  form_dropdown('_filials_rid', $this->filials_model->GetPairArr(), $this->validation->_filials_rid?$this->validation->_filials_rid:$content['DS']->_filials_rid);
			# } _filials_rid
						
			# { bdate 
			$content['bdate'] = $this->RenderLabel('bdate'); 
			$data = array('name'=>'bdate', 'id'=>'bdate', 'value'=>$this->validation->bdate?$this->validation->bdate:$content['DS']->bdate, 'size'=>'12', 'readonly'=>'readonly');
			$content['bdate_field'] =  form_input($data).$this->RenderCalendar('bdate');
			# } bdate
			
			# { edate
			$content['edate'] = $this->RenderLabel('edate'); 
			$data = array('name'=>'edate', 'id'=>'edate', 'value'=>$this->validation->edate?$this->validation->edate:$content['DS']->edate, 'size'=>'12', 'readonly'=>'readonly');
			$content['edate_field'] =  form_input($data).$this->RenderCalendar('edate');
			# } edate
			
			# { summ_value
			$content['summ_value'] = $this->RenderLabel('summ_value');
			$content['summ_value_field'] =  form_input('summ_value', $this->validation->summ_value?$this->validation->summ_value:$content['DS']->summ_value);
			# } summ_value
			
			# { oper_date
			$content['oper_date'] = $this->RenderLabel('oper_date');
			$data = array('name'=>'oper_date', 'id'=>'oper_date', 'value'=>$this->validation->oper_date?$this->validation->oper_date:$content['DS']->oper_date, 'size'=>'12', 'readonly'=>'readonly');
			$content['oper_date_field'] =  form_input($data).$this->RenderCalendar('oper_date');
			# } oper_date

			# { oper_type
			$content['oper_type'] = $this->RenderLabel('oper_type');
			$content['oper_type_field'] =  form_checkbox('oper_type', 'F', ($this->validation->oper_type=='F' || $content['DS']->oper_type == 'F')?True:False);
			# } oper_type
			
			# { descr
			$content['descr'] =  $this->lang->line('DESCR');
			$data = array('name'=>'descr', 'id'=>'descr', 'cols'=>'50', 'rows'=>'2', 'value'=>$this->validation->descr?$this->validation->descr:$content['DS']->descr); 
			$content['descr_field'] =  form_textarea($data);
			# } descr

			# { archive
			$content['archive'] =  $this->lang->line('ARCHIVE');
			$content['archive_field'] =  form_dropdown('archive', array('0'=>$this->lang->line('NO'), '1'=>$this->lang->line('YES')), $this->validation->archive?$this->validation->archive:$content['DS']->archive);
			# } archive
			
			# { modifyDT
			$content['modifyDT'] =  $this->lang->line('MODIFYDT');
			$content['modifyDT_field'] =  form_input('modifyDT', $this->validation->modifyDT?$this->validation->modifyDT:$content['DS']->modifyDT);
			# } modifyDT
			return $this->load->view('advertises/edit', $content, True);
		}
		if($this->advertises_model->UpdateRecord()){
			$this->load->view('standart/tmpl/edit_success', array('identifier'=>$this->GetIdentifier()));
		}
	}
	
	private function _details(){
			if($activerecord=$this->uri->segment(3)) $this->_setactiverecord($activerecord);
			$content = array();
			$content['DS'] = $this->advertises_model->GetEditDS();
			$content['header'] = $this->load->view('standart/tmpl/header', array('title'=>$this->lang->line('DICTIONARY_TITLE_CREATE')), True);
			$content['title'] = $this->lang->line('DICTIONARY_TITLE_CREATE'); 
			# { date_doc
			$content['date_doc'] = $this->lang->line('DATE_DOC');
			$data = array('name'=>'date_doc', 'id'=>'date_doc', 'size'=>'12', 'value'=>$this->validation->date_doc?$this->validation->date_doc:$content['DS']->date_doc, 'readonly'=>'readonly');
			$content['date_doc_field'] =  form_input($data);
			# } date_doc
			
			# { advertises_name
			$content['advertises_name'] = $this->RenderLabel('advertises_name');
			$content['advertises_name_field'] =  form_input('advertises_name', $this->validation->advertises_name?$this->validation->advertises_name:$content['DS']->advertises_name);
			# } advertises_name
			
			# { _currencies_rid
			$content['_currencies_rid'] = $this->lang->line('CURRENCY');
			$content['_currencies_rid_field'] =  form_dropdown('_currencies_rid', $this->currencies_model->GetPairArr(), $this->validation->_currencies_rid?$this->validation->_currencies_rid:$content['DS']->_currencies_rid);
			# } _currencies_rid
			
			# { _cities_rid
			$content['_cities_rid'] = $this->lang->line('CURRENCY');
			$content['_cities_rid_field'] =  form_dropdown('_cities_rid', $this->cities_model->GetPairArr(), $this->validation->_cities_rid?$this->validation->_cities_rid:$content['DS']->_cities_rid);
			# } _cities_rid
			
			# { _advertisessources_rid
			$content['_advertisessources_rid'] = $this->lang->line('SOURCE'); 
			$content['_advertisessources_rid_field'] =  form_dropdown('_advertisessources_rid', $this->advertisessources_model->GetPairArr(), $this->validation->_advertisessources_rid?$this->validation->_advertisessources_rid:$content['DS']->_advertisessources_rid);
			# } _advertisessources_rid

			# { _advertisescompanies_rid
			$content['_advertisescompanies_rid'] = $this->lang->line('SOURCE'); 
			$content['_advertisescompanies_rid_field'] =  form_dropdown('_advertisescompanies_rid', $this->advertisescompanies_model->GetPairArr(), $this->validation->_advertisescompanies_rid?$this->validation->_advertisescompanies_rid:$content['DS']->_advertisescompanies_rid);
			# } _advertisescompanies_rid
			
			# { _filials_rid
			$content['_filials_rid'] = $this->lang->line('FILIAL'); 
			$content['_filials_rid_field'] =  form_dropdown('_filials_rid', $this->filials_model->GetPairArr(), $this->validation->_filials_rid?$this->validation->_filials_rid:$content['DS']->_filials_rid);
			# } _filials_rid
						
			# { bdate 
			$content['bdate'] = $this->lang->line('BDATE');
			$data = array('name'=>'bdate', 'id'=>'bdate', 'value'=>$this->validation->bdate?$this->validation->bdate:$content['DS']->bdate, 'size'=>'12', 'readonly'=>'readonly');
			$content['bdate_field'] =  form_input($data);
			# } bdate
			
			# { edate
			$content['edate'] = $this->lang->line('EDATE');
			$data = array('name'=>'edate', 'id'=>'edate', 'value'=>$this->validation->edate?$this->validation->edate:$content['DS']->edate, 'size'=>'12', 'readonly'=>'readonly');
			$content['edate_field'] =  form_input($data);
			# } edate
			
			# { summ_value
			$content['summ_value'] = $this->lang->line('PRICE'); 
			$content['summ_value_field'] =  form_input('summ_value', $this->validation->summ_value?$this->validation->summ_value:$content['DS']->summ_value);
			# } summ_value
			
			# { oper_date
			$content['oper_date'] = $this->lang->line('PDATE'); 
			$data = array('name'=>'oper_date', 'id'=>'oper_date', 'value'=>$this->validation->oper_date?$this->validation->oper_date:$content['DS']->oper_date, 'size'=>'12', 'readonly'=>'readonly');
			$content['oper_date_field'] =  form_input($data).$this->RenderCalendar('oper_date');
			# } oper_date

			# { oper_type
			$content['oper_type'] = $this->lang->line('PLANED'); 
			$content['oper_type_field'] =  form_checkbox('oper_type', 'F', ($this->validation->oper_type=='F' || $content['DS']->oper_type == 'F')?True:False);
			# } oper_type
			
			# { descr
			$content['descr'] =  $this->lang->line('DESCR');
			$data = array('name'=>'descr', 'id'=>'descr', 'cols'=>'50', 'rows'=>'2', 'value'=>$this->validation->descr?$this->validation->descr:$content['DS']->descr); 
			$content['descr_field'] =  form_textarea($data);
			# } descr

			# { archive
			$content['archive'] =  $this->lang->line('ARCHIVE');
			$content['archive_field'] =  form_dropdown('archive', array('0'=>$this->lang->line('NO'), '1'=>$this->lang->line('YES')), $this->validation->archive?$this->validation->archive:$content['DS']->archive);
			# } archive
			
			# { modifyDT
			$content['modifyDT'] =  $this->lang->line('MODIFYDT');
			$content['modifyDT_field'] =  form_input('modifyDT', $this->validation->modifyDT?$this->validation->modifyDT:$content['DS']->modifyDT);
			# } modifyDT
			return $this->load->view('advertises/details', $content, True);
	}

	private function _remove(){
		if($activerecord=$this->uri->segment(3)) $this->_setactiverecord($activerecord);
		$this->advertises_model->DeleteRecord();
		$this->SetSessionData('activerecord', null);
		echo $this->_journal();
	}
	
	private function _find(){
		if (!isset($_POST['goFind'])){
			$content = array();
			$content['header'] = $this->load->view('standart/tmpl/header', array('title'=>$this->lang->line('DICTIONARY_TITLE_FIND')), True);
			$content['title'] = $this->lang->line('DICTIONARY_TITLE_FIND'); 

			# { date_doc_from
			$content['date_doc_from'] = $this->lang->line('DATE_DOC_FROM');
			$data = array('name'=>'date_doc_from', 'id'=>'date_doc_from', 'readonly'=>'readonly', 'size'=>'12'); 
			$content['date_doc_from_field'] = form_input($data).$this->RenderCalendar('date_doc_from');
			# } date_doc_from

			# { date_doc_to
			$content['date_doc_to'] = $this->lang->line('DATE_DOC_TO');
			$data = array('name'=>'date_doc_to', 'id'=>'date_doc_to', 'readonly'=>'readonly', 'size'=>'12'); 
			$content['date_doc_to_field'] = form_input($data).$this->RenderCalendar('date_doc_to');
			# } date_doc_to

			# { advertises_name
			$content['advertises_name'] = $this->RenderLabel('advertises_name');
			$content['advertises_name_field'] =  form_input('advertises_name');
			# } advertises_name
			
			$content['_currencies_rid'] = $this->lang->line('CURRENCY');
			$content['_currencies_rid_field'] =  form_dropdown('_currencies_rid', $this->currencies_model->GetPairArr());

			$content['_cities_rid'] = $this->lang->line('CITY');
			$content['_cities_rid_field'] =  form_dropdown('_cities_rid', $this->cities_model->GetPairArr());
			
			# { _advertisessources_rid
			$content['_advertisessources_rid'] = $this->lang->line('SOURCE'); 
			$content['_advertisessources_rid_field'] =  form_dropdown('_advertisessources_rid', $this->advertisessources_model->GetPairArr());
			# } _advertisessources_rid

			# { _advertisescompanies_rid
			$content['_advertisescompanies_rid'] = $this->lang->line('SOURCE'); 
			$content['_advertisescompanies_rid_field'] =  form_dropdown('_advertisescompanies_rid', $this->advertisescompanies_model->GetPairArr());
			# } _advertisescompanies_rid
			
			# { _filials_rid
			$content['_filials_rid'] = $this->lang->line('FILIAL'); 
			$content['_filials_rid_field'] =  form_dropdown('_filials_rid', $this->filials_model->GetPairArr());
			# } _filials_rid
						
			# { descr
			$content['descr'] =  $this->lang->line('DESCR');
			$data = array('name'=>'descr', 'id'=>'descr', 'cols'=>'50', 'rows'=>'2'); 
			$content['descr_field'] =  form_textarea($data);
			# } descr

			# { archive
			$content['archive'] =  $this->lang->line('ARCHIVE');
			$content['archive_field'] =  form_dropdown('archive', array('  '=>'', '0'=>$this->lang->line('NO'), '1'=>$this->lang->line('YES')));
			# } archive
			
			return $this->load->view('advertises/find', $content, True);			
		}
		$searchRule = array();
		if(isset($_POST['date_doc_from']) && trim($_POST['date_doc_from'])) $searchRule['_advertises_headers.date_doc>='] = trim($_POST['date_doc_from']);
		if(isset($_POST['date_doc_to']) && trim($_POST['date_doc_to'])) $searchRule['_advertises_headers.date_doc<='] = trim($_POST['date_doc_to']);
		if(isset($_POST['advertises_name']) && trim($_POST['advertises_name'])) $searchRule['_advertises_rows.advertises_name'] = trim($_POST['advertises_name']);
		if(isset($_POST['_currencies_rid']) && trim($_POST['_currencies_rid'])) $searchRule['_advertises_rows._currencies_rid'] = trim($_POST['_currencies_rid']);
		if(isset($_POST['_cities_rid']) && trim($_POST['_cities_rid'])) $searchRule['_advertises_rows._cities_rid'] = trim($_POST['_currencies_rid']);
		if(isset($_POST['_advertisessources_rid']) && trim($_POST['_advertisessources_rid'])) $searchRule['_advertises_rows._advertisessources_rid'] = trim($_POST['_advertisessources_rid']);
		if(isset($_POST['_advertisescompanies_rid']) && trim($_POST['_advertisescompanies_rid'])) $searchRule['_advertises_rows._advertisescompanies_rid'] = trim($_POST['_advertisescompanies_rid']);
		if(isset($_POST['_filials_rid']) && trim($_POST['_filials_rid'])) $searchRule['_advertises_rows._filials_rid'] = trim($_POST['_filials_rid']);
		if(isset($_POST['descr']) && trim($_POST['descr'])) $searchRule['_users.descr'] = trim($_POST['descr']);
		if(isset($_POST['archive']) && trim($_POST['archive'])) $searchRule['_users.archive'] = trim($_POST['archive']);
		if($searchRule){
			$this->_setsearchrule($searchRule);
		}
		if($_POST['goFind']=='2'){
			redirect('advertises', 'refresh');
		}
		$this->load->view('standart/tmpl/find_success', array('identifier'=>$this->GetIdentifier()));
	}
	
	private function _refresh(){
		$this->RefreshSessionData();
		echo $this->_journal();
	}
	
}

?>